﻿using System;
using UnityEngine;

// Token: 0x0200006E RID: 110
public class GuideDrive_Rot : GuideDrive
{
	// Token: 0x06000388 RID: 904 RVA: 0x000165C4 File Offset: 0x000147C4
	private void Start()
	{
		base.Init();
	}

	// Token: 0x06000389 RID: 905 RVA: 0x000165CC File Offset: 0x000147CC
	private void Update()
	{
		if (this.onMove)
		{
			Vector3 vector = Camera.main.transform.rotation * Vector3.forward;
			Vector3 vector2 = base.transform.rotation * new Vector3(1f, 0f, 0f);
			float num = Vector3.Angle(vector, vector2);
			Vector3 zero = Vector3.zero;
			float f = Vector3.Dot(vector, vector2);
			if (Mathf.Abs(f) > this.sideDot)
			{
				Vector3 position = this.PlanePos(Input.mousePosition);
				Vector3 vector3 = Quaternion.Euler(0f, 90f, 0f) * base.transform.InverseTransformPoint(this.prevPlanePos);
				Vector3 vector4 = Quaternion.Euler(0f, 90f, 0f) * base.transform.InverseTransformPoint(position);
				this.prevPlanePos = position;
				float num2 = GuideDrive_Rot.Vector2_VectorsToAngle(new Vector2(vector3.x, vector3.y), new Vector2(vector4.x, vector4.y));
				if (this.moveType == GuideDrive_Rot.MoveType.X)
				{
					zero.x = num2;
				}
				if (this.moveType == GuideDrive_Rot.MoveType.Y)
				{
					zero.y = num2;
				}
				if (this.moveType == GuideDrive_Rot.MoveType.Z)
				{
					zero.z = num2;
				}
			}
			else
			{
				Vector3 mousePosition = Input.mousePosition;
				mousePosition.z = Vector3.Distance(this.prevPlanePos, Camera.main.transform.position);
				Vector3 movePrevPos = this.movePrevPos;
				movePrevPos.z = Vector3.Distance(this.prevPlanePos, Camera.main.transform.position);
				Vector3 b = Camera.main.ScreenToWorldPoint(mousePosition) - Camera.main.ScreenToWorldPoint(movePrevPos);
				Vector3 position2 = this.prevPlanePos + b;
				Vector3 vector5 = Quaternion.Euler(0f, 90f, 0f) * base.transform.InverseTransformPoint(this.prevPlanePos);
				Vector3 vector6 = Quaternion.Euler(0f, 90f, 0f) * base.transform.InverseTransformPoint(position2);
				this.prevPlanePos = position2;
				float num3 = GuideDrive_Rot.Vector2_VectorsToAngle(new Vector2(vector5.x, vector5.y), new Vector2(vector6.x, vector6.y));
				if (this.moveType == GuideDrive_Rot.MoveType.X)
				{
					zero.x = num3;
				}
				if (this.moveType == GuideDrive_Rot.MoveType.Y)
				{
					zero.y = num3;
				}
				if (this.moveType == GuideDrive_Rot.MoveType.Z)
				{
					zero.z = num3;
				}
			}
			this.manager.DriveMoveRotation(Quaternion.Euler(zero));
			if (Input.GetMouseButtonUp(0))
			{
				this.OnMoveEnd();
				this.manager.OnMoveEnd(this);
			}
			this.movePrevPos = Input.mousePosition;
		}
	}

	// Token: 0x0600038A RID: 906 RVA: 0x000168A8 File Offset: 0x00014AA8
	public override void OnMoveStart(Vector3 clickPos)
	{
		this.onMove = true;
		this.movePrevPos = Input.mousePosition;
		this.manager.OnMoveStart(this);
		this.prevPlanePos = this.PlanePos(Input.mousePosition);
	}

	// Token: 0x0600038B RID: 907 RVA: 0x000168DC File Offset: 0x00014ADC
	private Vector3 PlanePos(Vector3 screenPos)
	{
		Vector3 inNormal = base.transform.rotation * new Vector3(1f, 0f, 0f);
		Plane plane = new Plane(inNormal, base.transform.position);
		Ray ray = Camera.main.ScreenPointToRay(screenPos);
		float distance = 0f;
		if (plane.Raycast(ray, out distance))
		{
			return ray.GetPoint(distance);
		}
		return this.manager.transform.position;
	}

	// Token: 0x0600038C RID: 908 RVA: 0x0001695C File Offset: 0x00014B5C
	public static float Vector2_VectorsToAngle(Vector2 v1, Vector2 v2)
	{
		float current = Mathf.Atan2(v1.x, v1.y) * 57.29578f;
		float target = Mathf.Atan2(v2.x, v2.y) * 57.29578f;
		return Mathf.DeltaAngle(current, target);
	}

	// Token: 0x04000318 RID: 792
	[SerializeField]
	private GuideDrive_Rot.MoveType moveType;

	// Token: 0x04000319 RID: 793
	[SerializeField]
	private float speed = 0.001f;

	// Token: 0x0400031A RID: 794
	[SerializeField]
	private float ringRadius = 0.065f;

	// Token: 0x0400031B RID: 795
	[SerializeField]
	private float sideDot = 0.1f;

	// Token: 0x0400031C RID: 796
	private Vector3 prevPlanePos;

	// Token: 0x0200006F RID: 111
	public enum MoveType
	{
		// Token: 0x0400031E RID: 798
		X = 1,
		// Token: 0x0400031F RID: 799
		Y,
		// Token: 0x04000320 RID: 800
		Z = 4
	}
}
